// Kony


#include "AbilitySystem/Abilitys/BasePassiveAbility.h"

#include "AbilitySystemBlueprintLibrary.h"
#include "AbilitySystem/BaseAbilitySystemComponent.h"

//激活能力时函数
void UBasePassiveAbility::ActivateAbility(const FGameplayAbilitySpecHandle Handle,const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, const FGameplayEventData* TriggerEventData)
{
	Super::ActivateAbility(Handle, ActorInfo, ActivationInfo, TriggerEventData);

	//获取能力系统组件 转换成 自定义能力系统组件
	if (UBaseAbilitySystemComponent* BaseASC = Cast<UBaseAbilitySystemComponent>(UAbilitySystemBlueprintLibrary::GetAbilitySystemComponent(GetAvatarActorFromActorInfo())))
	{
		//绑定接收取消被动广播委托 回调函数
		BaseASC->DeactivatePassiveAbilityDelegate.AddUObject(this, &UBasePassiveAbility::ReceiveDeactivate);
	}
}
//接收取消被动技能 广播回调函数
void UBasePassiveAbility::ReceiveDeactivate(const FGameplayTag& AbilityTag)
{
	//判断当前的能力标签中 是否包含 当前标签
	if (AbilityTags.HasTagExact(AbilityTag))
	{
		//终止该能力 (当前规格句柄，当前角色信息，当前激活信息，是否结束，是否取消)
		EndAbility(CurrentSpecHandle, CurrentActorInfo, CurrentActivationInfo, true, true);
	}
}
